export function getRequest(url, data) {
  return request(url, data, 'GET');
}

export function postRequest(url, data) {
  return request(url, data, 'POST');
}

export function deleteRequest(url, data) {
  return request(url, data, 'DELETE');
}

export function putRequest(url, data) {
  return request(url, data, 'PUT');
}

function request(url, data, method) {
  return new Promise((resolve, reject) => {
    const token = uni.getStorageSync('token');
    uni.request({
      url: "http://localhost:6090/api" + url,
      data,
      method,
      header: {
        'Authorization': token,
        'Content-Type': 'application/json' // 设置请求头Content-Type为application/json
      },
      success: res => {
        resolve(res.data)
      },
      fail: err => {
        reject(err)
      }
    })
  })
}